package com.dwsoft.word;

import com.dwsoft.xml.XBar;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author sqw
 * @version 1.0
 * @description TODO
 * @ClassName WBar
 * @Date 2020/8/14
 * @since jdk1.8
 */
@Component("bar")
public class WBar extends WChart<XBar>{

    @Override
    protected JFreeChart initializeChart(XBar chartNode){
        String dataKpi = chartNode.getDataKpi();
        String xAxis = chartNode.getXAxis();
        String yAxis = chartNode.getYAxis();
        List<Map<String,String>> rs = data(dataKpi);
        DefaultCategoryDataset dataset=new DefaultCategoryDataset();
        for(Map<String,String> data : rs){
            dataset.setValue(Integer.parseInt(String.valueOf(data.get(yAxis))),data.get(chartNode.getLegeng()),data.get(xAxis));
        }
        ChartFactory.setChartTheme(chartThemes.get("standard"));
        JFreeChart chart = ChartFactory.createBarChart3D(chartNode.getTitle(),chartNode.getXAxisLable(),
                chartNode.getYAxisLable(), dataset, PlotOrientation.VERTICAL, true, true, false);
        return chart;
    }
}
